
package DBLayer;
import java.sql.*;

/**
 * @version 12/22/2011
 * @author Gruppe 4
 */

public class GetCity implements IFDBGetCity 
{
    /**
     * Method to get the city from the database
     * @param zipCode int zipCode the zipCode of the city we want to get from the database
     * @return returns city a String with the name of the city
     */
    @Override
    public String getCity(int zipCode)
    {
        String query = "Select City FROM ZipCode where  zipCode = "+ zipCode;
        ResultSet results;
        String city = "";
        
        System.out.println("getCity Query: "+ query);
        try
        {
	   Statement stmt = DBConnection.getInstance().getDBcon().createStatement();
	   results = stmt.executeQuery(query);
	   if(results.next())
           {
               city = results.getString(1);
           }//end if
        }//end try
        catch(Exception e)
        {
	    System.out.println("getCity exception: Error in reading city: " + e.getMessage());
	}
        return city;
    }  
}